package com.jyw.business.obstacles.domain.vo.web;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.jyw.business.obstacles.constant.OrderCurrStateConstant;
import com.jyw.common.constant.SysDictTypeConstant;
import com.jyw.common.annotation.Conversion;
import com.jyw.common.enums.ConversionType;
import com.jyw.system.utils.DeptUtils;
import com.jyw.system.utils.TeamUtils;
import com.jyw.system.utils.UserUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.FieldNameConstants;

import java.util.Date;

/**
 * @author 沈峻
 * @ClassName LinkOrderVO
 * @Description 相关工单返回实体
 * @Date 2023/9/8 14:39
 **/
@Data
@ApiModel("相关工单返回实体")
@FieldNameConstants
public class LinkOrderVO {

    @ApiModelProperty("工单号")
    private String orderNum;

    @ApiModelProperty("工单状态")
    @Conversion(value = ConversionType.DICT,dictType = SysDictTypeConstant.OBS_FAULT_STATE)
    private String currState;

    @ApiModelProperty("工单状态标签")
    private String currStateToName;

    @ApiModelProperty("故障描述")
    private String faultRemark;

    @ApiModelProperty("处理人")
    private String makeUser;

    @ApiModelProperty(hidden = true,value = "派单对象标识")
    private String sendObjId;

    @ApiModelProperty(hidden = true,value = "派单对象类型")
    private String sendType;

    @ApiModelProperty("影响范围")
    @Conversion(value = ConversionType.DICT,dictType = SysDictTypeConstant.OBS_FAULT_RANGE)
    private Integer rangeType;

    @ApiModelProperty("影响范围标签")
    private String rangeTypeToName;

    @ApiModelProperty("报修时间")
    @JsonFormat(pattern = "yyyy-MM-hh HH:mm:dd")
    private Date createTime;

    public void processMakeUser() {
        //处理人数据处理
        if (getCurrState().equals(OrderCurrStateConstant.WAIT_ACCEPT)) {
            if(getSendType().equals(1)){
                setMakeUser(UserUtils.userIdToName(getSendObjId()));
            } else if (getSendType().equals(2)) {
                setMakeUser(TeamUtils.teamIdToName(getSendObjId()));
            } else if (getSendType().equals(3)) {
                setMakeUser(DeptUtils.deptIdToName(getSendObjId()));
            }
        } else if (getCurrState().equals(OrderCurrStateConstant.PROCESSING)) {
            setMakeUser(UserUtils.userIdToName(getSendObjId()));
        }

    }
}
